package com.api.shopapi.mapper;

import com.api.shopapi.entity.Message;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface MessageMapper {
    @Insert("insert into message " +
            "(" +
            "MessageCode," +
            "UserCodeFrom," +
            "UserCodeTo," +
            "Title," +
            "Content," +
            "CreateTime," +
            "SendTime," +
            "ReadTime," +
            "FileUrl," +
            "GovernmentCode," +
            "Status" +
            ") " +
            "values" +
            "(" +
            "#{message.MessageCode}," +
            "#{message.UserCodeFrom}," +
            "#{message.UserCodeTo}," +
            "#{message.Title}," +
            "#{message.Content}," +
            "#{message.CreateTime}," +
            "#{message.SendTime}," +
            "#{message.ReadTime}," +
            "#{message.FileUrl}," +
            "#{message.GovernmentCode}," +
            "#{message.Status}" +
            ")")
    public int insert(@Param("message") Message message);


    @Delete("delete from message where messageCode=#{messageCode}")
    public int deleteByMessageCode(@Param("messageCode") String messageCode);


    @Update("update message set " +
            "UserCodeFrom=#{message.UserCodeFrom}," +
            "UserCodeTo=#{message.UserCodeTo}," +
            "Title=#{message.Title}," +
            "Content=#{message.Content}," +
            "CreateTime=#{message.CreateTime}," +
            "SendTime=#{message.SendTime}," +
            "ReadTime=#{message.ReadTime}," +
            "FileUrl=#{message.FileUrl}," +
            "GovernmentCode=#{message.GovernmentCode}," +
            "Status=#{message.Status} " +
            "where MessageCode=#{message.MessageCode}")
    public int updateByMessageCode(@Param("message") Message message);

    @Select("select * from message where messageCode=#{messageCode} limit 1")
    public Message getByMessageCode(@Param("messageCode") String messageCode);

    @Select("select * from message")
    public List<Message> getList();
}
